/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package monitoring.mapping;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import monitoring.beans.XLS.MonitoringXLS;
import monitoring.beans.database.MonitoringDB;
import monitoring.beans.database.*;

/**
 *
 * @author Regulus
 */
public class DBtoXLS {

    public List<MonitoringXLS> mapping(List<MonitoringDB> listDb) throws ParseException {

        //mapeia cada item MonitoringDB para MonitoringXLS

        List<MonitoringXLS> listXls = new ArrayList<MonitoringXLS>();
        for (int i = 0; i < listDb.size(); i++) {

            MonitoringXLS monitObjXls = new MonitoringXLS();
            if (!listDb.isEmpty()) {
                monitObjXls.setAltitude(listDb.get(i).getHeight()!=null?listDb.get(i).getHeight():null);
                monitObjXls.setAmostralNumber(listDb.get(i).getAmostralNumber());
                monitObjXls.setCatalogNumber(listDb.get(i).getOcurrenceElement().getCatalogNumber());
                monitObjXls.setCity(listDb.get(i).getLocalityElement().getMunicipality().getMunicipality());
                monitObjXls.setCollectionCode(listDb.get(i).getRecordLevelElement().getCollectionCode().getCollectionCode());
                      
           
                    //fDate.parse(w.getFormattedText(k, 19).trim())
                monitObjXls.setCollectionDate(listDb.get(i).getCollectDate());
                monitObjXls.setCollectionName(listDb.get(i).getRecordLevelElement().getCollectionCode().getCollectionCode());
                monitObjXls.setCollectionTechinique(listDb.get(i).getTechnicalCollection().getTechinicalCollection());
                monitObjXls.setCollectionTime(listDb.get(i).getCollectTime());
                monitObjXls.setCollector(listDb.get(i).getCollector().getCollector());
                monitObjXls.setComplementaryDataOfLocation(listDb.get(i).getLocalityElement().getLocationRemark());
                //-string para int-PROBLEMA AQUI
                monitObjXls.setCoordinatePrecision(listDb.get(i).getLocalityElement().getCoordinatePrecision());
                monitObjXls.setCountry(listDb.get(i).getLocalityElement().getCountry().getCountry());
                monitObjXls.setCultivate(listDb.get(i).getCultivar().getCultivar());
                monitObjXls.setCulture(listDb.get(i).getCulture().getCulture());
                monitObjXls.setDenomination(listDb.get(i).getDenomination().getDenomination());
     
                monitObjXls.setFamily(listDb.get(i).getTaxonomicElement().getFamily().getFamily());
                monitObjXls.setFloorHeight(listDb.get(i).getFloorHeight());
                monitObjXls.setGenus(listDb.get(i).getTaxonomicElement().getGenus().getGenus());
                monitObjXls.setGeodeticDatum(listDb.get(i).getGeospatialElement().getGeodeticDatum());
                monitObjXls.setGpsReferencePoints(listDb.get(i).getGeospatialElement().getReferencePoints());
                monitObjXls.setIdgeral(listDb.get(i).getIdGeral());
                monitObjXls.setInstalationDate(listDb.get(i).getInstallationDate());
                monitObjXls.setInstalationTime(listDb.get(i).getInstallationTime());
                monitObjXls.setInstitutionCode(listDb.get(i).getRecordLevelElement().getInstitutionCode().getInstitutionCode());
                monitObjXls.setLatitude(listDb.get(i).getGeospatialElement().getDecimalLatitude());
                if(listDb.get(i).getWidth()==null&&listDb.get(i).getLength()==null&&listDb.get(i).getHeight()==null)
                    monitObjXls.setLcaDimensions("");
                else
                    monitObjXls.setLcaDimensions((listDb.get(i).getWidth()!=null?listDb.get(i).getWidth():"") + "/" + (listDb.get(i).getLength()!=null?listDb.get(i).getLength():"") + "/" + (listDb.get(i).getHeight()!=null?listDb.get(i).getHeight():""));
                monitObjXls.setLocation(listDb.get(i).getLocalityElement().getLocality().getLocality());
                monitObjXls.setLongitude(listDb.get(i).getGeospatialElement().getDecimalLongitude());
                monitObjXls.setOrder(listDb.get(i).getTaxonomicElement().getOrder().getOrder());
                monitObjXls.setPanTrapColor(listDb.get(i).getColorPanTrap().getColorPanTrap());
                monitObjXls.setPlotNumber(listDb.get(i).getPlotNumber());
                monitObjXls.setPopularName(listDb.get(i).getTaxonomicElement().getVernacularName());
                monitObjXls.setPredominatBiome(listDb.get(i).getPredominantBiome().getPredominantBiome());
                monitObjXls.setScientificName(listDb.get(i).getTaxonomicElement().getScientificName().getScientificName());
                monitObjXls.setSex(listDb.get(i).getOcurrenceElement().getSex().getSex());
                monitObjXls.setSpecies(listDb.get(i).getTaxonomicElement().getSpeciesName().getSpeciesName());
                monitObjXls.setState(listDb.get(i).getLocalityElement().getStateProvince().getStateProvince());
                monitObjXls.setSubSpecies(listDb.get(i).getTaxonomicElement().getSubSpecies().getSubSpecies());
                monitObjXls.setSubTribe(listDb.get(i).getTaxonomicElement().getSubTribe().getSubTribe());
                monitObjXls.setSupporttype(listDb.get(i).getSupportType().getSupportType());
                monitObjXls.setSurroundingsVegetation(listDb.get(i).getSurroundingsVegetation().getSurroundingsVegetation());
                monitObjXls.setSurroundingsCulture(listDb.get(i).getSurroundingsCulture().getSurroundingsCulture());
                monitObjXls.setTribe(listDb.get(i).getTaxonomicElement().getTribe().getTribe());                                
                monitObjXls.setWeight(listDb.get(i).getWeight());
                monitObjXls.setDigitizer(listDb.get(i).getDigitizer().getDigitizer());
                monitObjXls.setGpsPrecision(listDb.get(i).getLocalityElement().getCoordinatePrecision());
                
                listXls.add(monitObjXls);
            }
        }
        return listXls;
    }
}
